﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;


public class BizTVHam
{
    public static byte[] imageToByteArray(System.Drawing.Image imageIn)
    {
        MemoryStream ms = new MemoryStream();
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        return ms.ToArray();
    }

    public static Image byteArrayToImage(byte[] byteArrayIn)
    {
        MemoryStream ms = new MemoryStream(byteArrayIn);
        Image returnImage = Image.FromStream(ms);
        return returnImage;
    }

    //Ham chuyen doi ve chuoi khong dau
    public static string ConvertToUnSign(string text)
    {
        for (int i = 33; i < 48; i++)
        {
            text = text.Replace(((char)i).ToString(), "");
        }

        for (int i = 58; i < 65; i++)
        {
            text = text.Replace(((char)i).ToString(), "");
        }

        for (int i = 91; i < 97; i++)
        {
            text = text.Replace(((char)i).ToString(), "");
        }

        for (int i = 123; i < 127; i++)
        {
            text = text.Replace(((char)i).ToString(), "");
        }

        //text = text.Replace(" ", "-"); //Comment lại để không đưa khoảng trắng thành ký tự -

        Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");
        string strFormD = text.Normalize(System.Text.NormalizationForm.FormD);
        return regex.Replace(strFormD, String.Empty).Replace('\u0111', 'd').Replace('\u0110', 'D');
    }
}



